//
//  BaseTableViewController.swift
//  01-SinaWeibo
//
//  Created by pc on 15/11/8.
//  Copyright © 2015年 file. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {

    //添加用户是否登记标记 - 
    //loadVIew是苹果专门为手写代码 准备的  等效与 sb / xib
    //一旦实现这个方法  xib / sb就自动失效
    //会自动检测 view是否为空  如果为空 会自动调用 loadView方法
    var userLogin = false
    var visitorLoginView: VisitorLoginView?
    
    override func loadView() {
        userLogin ? super.loadView() : loadVisitorView()
        
    }
    
    private func loadVisitorView(){
    
        //view 的大小 在view 就会设置
        visitorLoginView = VisitorLoginView()
        
        //设置代理
        visitorLoginView?.visitorDelegate = self
       view = visitorLoginView
    
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorWillRegister")
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorWillLogin")
    }
    
    //MARK: visitorDelegate 协议方法
    func visitorWillRegister() {
        print("come on")
        
        
    }
    
    func visitorWillLogin() {
        print("come in")
    
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        
        presentViewController(nav, animated: true, completion: nil)
    
           }
    
    
    
    
    
    
    
    
    
    
    
    
    //视图控制器
    override func viewDidLoad() {
        super.viewDidLoad()

        
      
        
        
        
    }



}
